<%--
  Created by IntelliJ IDEA.
  User: 苗苗
  Date: 2024/5/11
  Time: 14:19
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript" src="resource/js/jquery.js"></script>
<script src="resource/js/jquery-2.1.0.min.js"></script>
<script src="resource/js/echarts.min.js"></script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Title</title>
    <link href="resource/css/style.css" rel="stylesheet" type="text/css">
    <link href="resource/css/select.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="resource/js/jquery.js"></script>
    <script type="text/javascript" src="resource/js/jquery.idTabs.min.js"></script>
    <script type="text/javascript" src="resource/js/select-ui.min.js"></script>
    <script type="text/javascript" src="resource/editor/kindeditor.js"></script>
    <script type="text/javascript">KE.show({
        id: 'content7',
        cssPath: './index.css'
    });
    </script>
    <script type="text/javascript">
        $(document).ready(function (e) {
            $(".select1").uedSelect({
                width: 345
            });
            $(".select2").uedSelect({
                width: 167
            });
            $(".select3").uedSelect({
                width: 100
            });
        });
        //限制手机号格式
        $(function () {

            $("#eno").hide()
            $("#no").hide()
            $("#back").click(function () {
                if ($("#uname").val() != '${user.uname}' | $("#sex").val() != '${user.sex}' |
                    $("#age").val() != '${user.age}' |
                    $("#password").val() != '${user.password}' | $("#phone").val() != '${user.phone}' |
                    $("#birthday").val() != '${user.birthday}' | $("#address").val() != '${user.address}'
                    | $("#email").val() != '${user.email}') {
                    var a = confirm("你已经修改了部分内容，要保存吗？")
                    if (a) {
                        var uname = $("#uname").val()
                        var sex = $("#sex").val()

                        var age = $("#age").val()
                        var password = $("#password").val()
                        var phone = $("#phone").val()
                        var birthday = $("#birthday").val()
                        var address = $("#address").val()
                        var email = $("#email").val()
                        $.ajax({
                            url: "updateUser",
                            type: "post",
                            data: {
                                "uname": uname, "sex": sex,
                                "age": age, "password": password,
                                "phone": phone, "birthday": birthday,
                                "address": address, "email": email
                            },
                        })
                        alert("修改成功")
                        window.location.href = "getUser"
                    } else {
                        window.location.href = "getUser"
                    }
                }
            })
            $("#xiugai").click(function () {
                if ($("#uname").val() == '${user.uname}' & $("#sex").val() == '${user.sex}' &
                    $("#age").val() == '${user.age}' &
                    $("#password").val() == '${user.password}' & $("#phone").val() == '${user.phone}' &
                    $("#birthday").val() == '${user.birthday}' & $("#address").val() == '${user.address}'
                    & $("#email").val() == '${user.email}') {
                    alert("你没有修改任何部分")
                } else {
                    var uname = $("#uname").val()
                    var sex = $("#sex").val()
                    var age = $("#age").val()
                    var password = $("#password").val()
                    var phone = $("#phone").val()
                    var birthday = $("#birthday").val()
                    var address = $("#address").val()
                    var email = $("#email").val()
                    $.ajax({
                        url: "updateUser",
                        type: "post",
                        data: {
                            "uname": uname, "sex": sex,
                            "age": age, "password": password,
                            "phone": phone, "birthday": birthday,
                            "address": address, "email": email
                        },
                    })
                    alert("修改成功")
                    window.location.href = "getUser"
                }


            })
            $("#phone").blur(function () {
                var s = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
                if (!s.test($("#phone").val())) {
                    $("#no").show()
                    $('#back').attr('disabled', true);
                    $('#xiugai').attr('disabled', true);
                } else {
                    $("#no").hide()
                    $('#back').attr('disabled', false);
                    $('#xiugai').attr('disabled', false);
                }
            })
            //限制邮件格式
            $("#email").blur(function () {
                var s = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
                if (!s.test($("#email").val())) {
                    $("#eno").show()
                    $('#back').attr('disabled', true);
                    $('#xiugai').attr('disabled', true);
                } else {
                    $("#eno").hide()
                    $('#back').attr('disabled', false);
                    $('#xiugai').attr('disabled', false);
                }
            })

            $("#img").click(function () {
                alert("工作头像更换请联系上级领导")
            })
        })


    </script>
</head>
<body>
<div class="formbody">
    <div id="usual1" class="usual">
        <ul class="forminfo">
            <li><label>部门<b>：</b></label><input name="dname" type="text" value="${user.dept.dname}" class="dfinput"
                                                disabled></li>
            <li><label>身份<b>：</b></label><input name="role" type="text" value="${user.role.role}" class="dfinput"
                                                disabled></li>
            <li><label>工号<b>：</b></label><input name="ucard" type="text" value="${user.ucard}" class="dfinput" disabled>
            </li>

            <li><label>头像<b>：</b></label>
                <img src="${user.image}" width="50px" id="img"></li>
            <li><label>姓名<b>：</b></label><input id="uname" type="text" value="${user.uname}" class="dfinput"></li>
            <li><label>住址<b>：</b></label><input id="address" type="text" value="${user.address}" class="dfinput"></li>


            <li><label>年龄<b>：</b></label><input id="age" name="age" type="text" value="${user.age}" class="dfinput"
                                                onkeyup="this.value=this.value.replace(/\D/g,'')">
            </li>
            <li><label>性别<b>：</b></label>
                <input id="sex" name="sex" type="text" value="${user.sex}" class="dfinput">
            </li>
            <li><label>密码<b>：</b></label><input id="password" name="password" type="password" value="${user.password}"
                                                class="dfinput"></li>
            <li><label>邮箱<b>：</b></label><input id="email" name="email" type="text" value="${user.email}"
                                                class="dfinput"><span id="eno" style="color: red">*邮件格式不合法请重新输入</span>
            </li>
            <li><label>手机号码<b>：</b></label><input id="phone" name="phone" type="text" value="${user.phone}"
                                                  onkeyup="this.value=this.value.replace(/\D/g,'')"
                                                  class="dfinput"><span id="no"
                                                                        style="color: red">*手机号码格式不正确请重新输入</span></li>

            <li><label>生日日期<b>：</b></label><input id="birthday" name="birthday" type="date" value="${user.birthday}"
                                                  class="dfinput"></li>
        </ul>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input id="back" type="button" class="loginbtn" value="返回"/>
        <input id="xiugai" type="button" class="loginbtn" value="修改"/>
    </div>
</div>

</body>
</html>

